correct computation of timestamp with garmin real time positioning. (#1302)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Mon, 22 Jul 2024 19:21:05 +0000 (13:21 -0600)
committerGitHub <noreply@github.com>
Mon, 22 Jul 2024 19:21:05 +0000 (13:21 -0600)
* correct computation of timestamp with garmin real time positioning.

* tweak garmin pvt conversion

garmin.cc

index 29036fd3e41163a16fd0935bcb975e1e34a58576..ca642c3e7d1facfa9ba7b3e1d22457af74b23ecc 100644 (file)
--- a/garmin.cc
+++ b/garmin.cc
@@ -22,7 +22,7 @@
 #include "garmin.h"
 
 #include <climits>               // for INT_MAX
-#include <cmath>                 // for atan2, floor, sqrt
+#include <cmath>                 // for atan2, modf, sqrt
 #include <cstdio>                // for fprintf, fflush, snprintf, snprintf
 #include <cstdint>               // for int32_t
 #include <cstdlib>               // for strtol
@@ -36,7 +36,7 @@
 #include <QString>               // for QString
 #include <QTextCodec>            // for QTextCodec
 #include <Qt>                    // for CaseInsensitive
-#include <QtGlobal>              // for qPrintable, foreach
+#include <QtGlobal>              // for qPrintable, qRound64, Q_INT64_C, qint64
 
 #include "defs.h"
 #include "formspec.h"            // for FormatSpecificDataList
@@ -596,11 +596,13 @@ GarminFormat::pvt2wpt(GPS_PPvt_Data pvt, Waypoint* wpt)
    * 3) The number of leap seconds that offset the current UTC and GPS
    *    reference clocks.
    */
-  double wptime = 631065600.0 + pvt->wn_days * 86400.0  +
-                  pvt->tow
-                  - pvt->leap_scnds;
-  double wptimes = floor(wptime);
-  wpt->SetCreationTime(wptimes, 1000000.0 * (wptime - wptimes));
+  double tow_integral_part;
+  double tow_fractional_part = modf(pvt->tow, &tow_integral_part);
+  qint64 seconds = Q_INT64_C(631065600) + pvt->wn_days * Q_INT64_C(86400)  +
+                   qRound64(tow_integral_part)
+                   - pvt->leap_scnds;
+  qint64 milliseconds = qRound64(1000.0 * tow_fractional_part);
+  wpt->SetCreationTime(seconds, milliseconds);
 
   /*
    * The Garmin spec fifteen different models that use a different